<{Tinclude "commom/admin_header"}>
 <section id="container" >


      <!--顶部-->
      <{Tinclude"commom/admin_inner_header"}>
      <!--顶部-->
      
       <{Tinclude"commom/admin_left_menu"}>
       
       <section id="main-content">
          <section class="wrapper">
          	<h3><i class="<{if $___menuinfo["iconclass"]}><{$___menuinfo["iconclass"]}><{else}>fa fa-list-ul<{/if}>"></i><{$___menuinfo["base_name"]}></h3>
                <div class="row mt">
                    <div class="col-md-12">
                       <div class="form-panel">  
                           
                           
                           <div class='col-md-2 col-sm-2'>
                               <a class='btn btn-default btn-sm' href="<{echo Common::RewriteUrl("Rental","zufangadd");}>"><span class="fa fa-user"></span>开房</a>
                               
                           </div>
                           <div class="col-md-10 col-sm-10 text-right">
                                   
                                 <form class="form-inline" method="post" action="<{echo Common::RewriteUrl($jp_arg["c"],$jp_arg["a"]);}>">
  <div class="form-group">

    <input type="text" name="seach_user_name" value="<?php if(isset($jp_arg['seach_user_name']))echo $jp_arg['seach_user_name'];?>" class="form-control" id="exampleInputName2" placeholder="租户姓名">
  </div>
   <div class="form-group">
   
    <input type="text" name="seach_room_no" value="<?php if(isset($jp_arg['seach_room_no']))echo $jp_arg['seach_room_no'];?>" class="form-control" id="exampleInputName3" placeholder="房间编号">
  </div>
  <button type="submit" class="btn btn-default">搜索</button>
</form>
                                   
                                   
                               </div>
                           <div class='clearfix'></div>
                           <div class='margin_top20'></div>
                           <div class="col-lg-12">
                           <div class="row">
                               
            <{if $list}>                         
  <section id="no-more-tables">                   
  <table class="table table-striped table-condensed table-hover cf">
      <thead class="cf">
        <tr>
            <th class="text-center">租户</th>
          <th class="text-center">房间</th>
          <th class="text-center">租金</th> 
          <th class="text-center">租房时间</th>
           <th class="text-center">状态</th>
          <th class="text-center">操作</th>
        </tr>
      </thead>
      <tbody>
   
          <{foreach $list as $item}>
          <tr>
              <td data-title="租户" class="text-center"> <{if $item["status"]!=0}><a href="<{echo Common::RewriteUrl("Rental","tuifang","&id=".$item["id"]);}>" ><{/if}><{$item["username"]}> <{if $item["status"]!=0}></a><{/if}></td>
              <td data-title="房间" class="text-center"><{$item["local"]}>-<{$item["layer_id"]}>楼-<{$item["room_no"]}></td>
              <td data-title="租金" class="text-center"><{$item["rent"]}></td>
              <td data-title="租房时间" class="text-center"><{echo date("Y-m-d",$item["create_time"]);}></td>
              <td data-title="状态" class="text-center"><{if $item["status"]==1}>新租客<{elseif $item["status"]==0}>搬走<{elseif $item["status"]==2}>稳定租房<{/if}></td>
              <td data-title="操作" class="text-center">
                  <{if $item["status"]!=0}>
                  <div class="btn-group">
                      <{if $item["status"]==1}>
                      <a class="btn btn-default btn-xs" href="<{echo Common::RewriteUrl("Rental","zufangedit","&id=".$item["id"]);}>" ><span class="glyphicon glyphicon-edit"></span>编辑</a>
                      <{/if}>
                      <a data-toggle="modal" data-target="#rentadd" title="交租" class="btn btn-primary btn-xs rentadd"  data-rid="<{$item["id"]}>"><span class="fa fa-cny"></span>交租</a>
                      <a data-toggle="tooltip" data-placement="right" title="退房" class="btn btn-danger btn-xs jppdelete" data-href="<{echo Common::RewriteUrl("Rental","tuifang","&id=".$item["id"]);}>"><span class="fa fa-unlock-alt"></span>退房</a>
              </div>
                  <{else}>
                   <{$item["tui_year"]}>年<{$item["tui_month"]}>月搬走
                  <{/if}>
              </td>
          </tr>
          <{/foreach}>
    
      </tbody>
  </table>
</section>
                              
                          <div class="col-md-12 text-center">
                           <?php Temp::Tinclude("commom/pager");?>
                          </div>
                     <{else}>
                        <div class="col-md-12 col-xs-12">
                                 <h4 class="text-center">数据为空</h4>
                             </div>
                        <{/if}>             
                               
                           </div>
                           </div>
                           <div class="clearfix"></div>
                           
                           
 
                           
                         
                           
                       </div>
                    </div>
                </div>
          </section>
       </section>
 </section>


<!--交房租-->
<div class="modal fade" id="rentadd" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="exampleModalLabel">缴纳房租</h4>
      </div>
      <div class="modal-body">
          <form id="myform">
           <input type="hidden" class="form-control" name="room_rel_user_id">
           <input type="hidden" class="form-control" name="room_id">
           <input type="hidden" class="form-control" name="user_id">
           <input type="hidden" class="form-control" name="needtopay">
           <input type="hidden" class="form-control" name="preshui_du">
           <input type="hidden" class="form-control" name="predian_du">
      <div class="form-group input-group col-md-12">
         <span class="input-group-addon">房间编号</span>
         <input type="text" class="form-control" readonly="readonly"  name="room_no" placeholder="房间编号">
      </div>
       <div class="form-group input-group col-md-12">
         <span class="input-group-addon">租户</span>
         <input type="text"  class="form-control" readonly="readonly"  name="user_name" placeholder="租户">
      </div>
           <div class="col-md-12 form-group">
               <p>选择缴纳房租的年月</p>
           </div>
           <div class="form-group  col-md-6 ">
               
               <select name="year" class="form-control">
                <option value="">2015年</option>
                <option value="">2016年</option>
              </select>
               
              
              
               
           </div> 
           <div class="form-group  col-md-6">
                <select name="month" class="form-control">
                <option value="">1月</option>
                <option value="">2月</option>
              </select>
           </div>
           
           
            <div class="form-group input-group col-md-12">
         <span class="input-group-addon">这个月水吨数</span>
          <input type="text" class="form-control" name="shui_du" value="0" placeholder="请输入这个月水吨数">        
          <span class="input-group-addon">(吨)</span>
      </div>
           
           <div class="form-group input-group col-md-12">
         <span class="input-group-addon">这个月电度数</span>
          <input type="text" class="form-control" name="dian_du" value="0" placeholder="请输入这个月电度数">        
          <span class="input-group-addon">(度)</span>
      </div>
           
      <div class="form-group input-group col-md-12">
         <span class="input-group-addon">这个月水费</span>
          <input type="text" class="form-control" name="l_water_price" value="0" placeholder="请输入这个月水费">        
          <span class="input-group-addon">(元)</span>
          <span class="input-group-addon" data-toggle="modal" data-target="#jisuanshuifei" data-inputname="l_water_price"><span class="fa fa-flask"></span></span>
      </div>
           
          
           
       <div class="form-group input-group col-md-12">
         <span class="input-group-addon">这个月电费</span>
          <input type="text" class="form-control" name="l_dian_price" value="0" placeholder="请输入这个月电费">        
          <span class="input-group-addon">(元)</span>
          <span class="input-group-addon" data-toggle="modal" data-target="#jisuandianfei" data-inputname="l_dian_price"><span class="fa fa-credit-card"></span></span>
      </div>
      <div class="form-group input-group col-md-12">
         <span class="input-group-addon">实收租金</span>
          <input type="text" class="form-control" name="rent" placeholder="请输入租金">        
          <span class="input-group-addon">(元/月)</span>
      </div>
           
     <div class="form-group input-group col-md-12">
         <span class="input-group-addon">实收水费</span>
          <input type="text" class="form-control" name="water_price" value="0" placeholder="请输入水费">        
          <span class="input-group-addon">(元)</span>
          <span class="input-group-addon" data-toggle="modal" data-target="#jisuanshuifei" data-inputname="water_price"><span class="fa fa-flask"></span></span>
      </div>
           
     <div class="form-group input-group col-md-12">
         <span class="input-group-addon">实收电费</span>
         <input type="text" class="form-control" name="dian_price" value="0" placeholder="请输入电费">        
          <span class="input-group-addon">(元)</span>
          <span class="input-group-addon" data-toggle="modal" data-target="#jisuandianfei" data-inputname="dian_price"><span class="fa fa-credit-card"></span></span>
      </div>
           
           <div class="col-md-12 form-group text-success">
               <p>总计金额:<span id="needpay"></span></p>
           </div>
           <div class="clearfix"></div>
          </form>
          
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-success" id="btnrentadd">提交</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      </div>
    </div>
  </div>
</div>
<!--end交房租-->



<script>
    function initdate(obj){
         var _now=new Date();
        var year=_now.getFullYear();
        var month=_now.getMonth()+1;
       if(obj.tui_month!=0){
           month=obj.tui_month;
       }
       if(obj.tui_year!=0){
           year=obj.tui_year;
       }
        var selectyear=$("select[name='year']");
        var selectmonth=$("select[name='month']");
        selectyear.empty();
        selectmonth.empty();
        for(var i=year-4;i<year+4;i++){
            if(obj.tui_year!=0&&i>obj.tui_year){
                break;
            }
            if(i==year){
                var option = $("<option>").val(i).text(i+"年");
                option.attr("selected",true);
            }else{
                var option = $("<option>").val(i).text(i+"年");
            }
            selectyear.append(option);
        }
        for(var j=1;j<=12;j++){
           if(obj.tui_month!=0&&j>obj.tui_month){
                break;
           }
          if(j==month){
                var option = $("<option>").val(j).text(j+"月份");
                option.attr("selected",true);
            }else{
                var option = $("<option>").val(j).text(j+"月份");
            }
            selectmonth.append(option);  
        }
    }
    $(document).ready(function(){
        $(".jppdelete").click(function(){
            var href=$(this).data("href");
            if(window.confirm("确定要退房吗?")){
                window.location.href=href;
            }
        });
        var selectyear=$("select[name='year']");
        var selectmonth=$("select[name='month']");
        selectyear.change(function(){
            getneedtopay();
        });
        selectmonth.change(function(){
            getneedtopay();
        });
    });
    $(function () {
  $('[data-toggle="tooltip"]').tooltip();
});
$('#rentadd').on('show.bs.modal', function (event){
    var button = $(event.relatedTarget);
    
    var id=button.data("rid");

    $.post("<{echo Common::RewriteUrl("Rental","public_ajax_userrelroom");}>",{"id":id},function(data){
        if(data.status==1){
            $("input[name='room_no']").val(data.data.room_no);
            $("input[name='user_name']").val(data.data.user_name);
            $("input[name='rent']").val(data.data.rent);
            $("input[name='needtopay']").val(data.data.rent);
            $("input[name='room_rel_user_id']").val(id);
            $("input[name='room_id']").val(data.data.room_id);
            $("input[name='user_id']").val(data.data.user_id);
            $("#needpay").html(data.data.rent+"元");
            initdate(data.data);
            getneedtopay();
            
        }
    },"json");

});


function getneedtopay(){
    $("#btnrentadd").attr("disabled",true);
    $.ajax({
        type:"POST",
        url:"<{echo Common::RewriteUrl("Rental","public_ajax_needtopay");}>",
        data:$("#myform").serialize(),
        async:true,
        dataType:"json",
        success:function(data){
            $("#btnrentadd").attr("disabled",false);
            if(data.status==1){
               $("input[name='rent']").val(data.msg);
               if(data.water_price){
                $("input[name='water_price']").val(data.water_price);
               }else{
                   $("input[name='water_price']").val(0);
               }
               if(data.dian_price){
               $("input[name='dian_price']").val(data.dian_price);
               }else{
                    $("input[name='dian_price']").val(0);
               }
               if(data.l_water_price){
                $("input[name='l_water_price']").val(data.l_water_price);
               
                }else{
                    $("input[name='l_water_price']").val(0);
                
                }
               if(data.l_dian_price){
                 $("input[name='l_dian_price']").val(data.l_dian_price);
               }else{
                   $("input[name='l_dian_price']").val(0);
                 
               }
               
               if(data.shui_du){
                 $("input[name='shui_du']").val(data.shui_du);
               }else{
                   $("input[name='shui_du']").val(0);
                 
               }
               if(data.dian_du){
                 $("input[name='dian_du']").val(data.dian_du);
               }else{
                   $("input[name='dian_du']").val(0);
                 
               }
               
                if(data.preshui_du){
                 $("input[name='preshui_du']").val(data.preshui_du);
               }else{
                   $("input[name='preshui_du']").val(0);
                 
               }
               
               if(data.predian_du){
                 $("input[name='predian_du']").val(data.predian_du);
               }else{
                   $("input[name='predian_du']").val(0);
                 
               }
               
               $("#needpay").html((parseInt(data.msg)+parseInt(data.dian_price?data.dian_price:0)+parseInt(data.water_price?data.water_price:0))+"元");
            }else{
                alert(data.msg);
            }
        }
    });
}
$("#btnrentadd").click(function(){
    $.ajax({
        type:"POST",
        url:"<{echo Common::RewriteUrl("Rental","public_ajax_jiaozu");}>",
        data:$("#myform").serialize(),
        async:false,
        dataType:"json",
        success:function(data){
            if(data.status==1){
                alert("缴纳成功!");
                $('#rentadd').modal('hide');
                window.location.reload();
            }else{
                alert(data.msg);
            }
        }
    });


});
 $("input[name='shui_du']").blur(function(){
     var predunshu=$("input[name='predunshu']").val();
     var shui_du=$("input[name='shui_du']").val();
     var dunshujiage=$("input[name='dunshujiage']").val();
      var zj=(shui_du-predunshu)*dunshujiage;
     $("input[name='l_water_price']").val(zj.toFixed(2));
 });
 
  $("input[name='dian_du']").blur(function(){
     var predian_du=$("input[name='predian_du']").val();
     var dian_du=$("input[name='dian_du']").val();
     var dushujiage=$("input[name='dushujiage']").val();
      var zj=(dian_du-predian_du)*dushujiage;
     $("input[name='l_dian_price']").val(zj.toFixed(2));
 });
</script>
<{Tinclude"commom/jisuandianfei_form"}>
<{Tinclude"commom/jisuanshuifei_form"}>
<{Tinclude"commom/admin_footer"}>